// pre-defined patterns for thr conway's game of life

class Pattern {
  constructor(name, structure, picPath) {
    this.structure = []
    this.name = name
    this.picPath = picPath
    var centerX = Math.floor(structure.length / 2)
    var centerY = Math.floor(structure[0].length / 2)
    for (var x = 0; x < structure.length; x++) {
      for (var y = 0; y < structure[0].length; y++) {
        if (structure[x][y] == 1) {
          this.structure.push([x - centerX, y - centerY])
        }
      }
    }
  }

  rotate() {
    for (var i = 0; i < this.structure.length; i++) {
      var x = this.structure[i][0]
      var y = this.structure[i][1]
      this.structure[i] = [-y, x]
    }
  }
}

const patterns = [
  new Pattern(
    'Glider',
    [
      [0, 1, 0],
      [0, 0, 1],
      [1, 1, 1],
    ],
    '../static/images/animation/Game_of_life_animated_glider.gif',
  ),
  new Pattern(
    'Blinker',
    [
      [0, 1, 0],
      [0, 1, 0],
      [0, 1, 0],
    ],
    '../static/images/animation/Game_of_life_blinker.gif',
  ),
  new Pattern(
    'Light Weight Space Ship',
    [
      [0, 1, 1, 1, 1],
      [1, 0, 0, 0, 1],
      [0, 0, 0, 0, 1],
      [1, 0, 0, 1, 0],
    ],
    '../static/images/animation/Game_of_life_animated_LWSS.gif',
  ),
  new Pattern(
    'Middle Weight Space Ship',
    [
      [0, 0, 1, 0, 0, 0],
      [1, 0, 0, 0, 1, 0],
      [0, 0, 0, 0, 0, 1],
      [1, 0, 0, 0, 0, 1],
      [0, 1, 1, 1, 1, 1],
    ],
    '../static/images/animation/Animated_Mwss.gif',
  ),
  new Pattern(
    'Heavy Weight Space Ship',
    [
      [0, 0, 1, 1, 0, 0, 0],
      [1, 0, 0, 0, 0, 1, 0],
      [0, 0, 0, 0, 0, 0, 1],
      [1, 0, 0, 0, 0, 0, 1],
      [0, 1, 1, 1, 1, 1, 1],
    ],
    '../static/images/animation/Animated_Hwss.gif',
  ),
  new Pattern(
    'Eater 1',
    [
      [1, 1, 0, 0],
      [1, 0, 1, 0],
      [0, 0, 1, 0],
      [0, 0, 1, 1],
    ],
    '../static/images/animation/Eater1.png',
  ),
  new Pattern(
    'Herschel',
    [
      [1, 0, 0, ],
      [1, 1, 1, ],
      [1, 0, 1, ],
      [0, 0, 1, ],
    ],
    '../static/images/animation/Herschel.png',
  ),
  new Pattern(
    'Babblingbrook',
    [
      [0, 0, 0, 0, 0, 0, 0, 1, 0, 0, 0, 0, 0, 0, 0, 0],
      [0, 0, 0, 0, 0, 1, 1, 1, 0, 0, 0, 0, 1, 1, 0, 0],
      [0, 0, 0, 0, 1, 0, 0, 0, 1, 1, 0, 0, 1, 0, 0, 0],
      [0, 1, 0, 0, 1, 0, 1, 1, 0, 0, 1, 0, 1, 0, 0, 0],
      [1, 0, 1, 0, 1, 0, 0, 0, 0, 1, 1, 0, 0, 1, 1, 0],
      [0, 1, 1, 0, 0, 1, 1, 0, 0, 0, 0, 1, 0, 1, 0, 1],
      [0, 0, 0, 1, 0, 1, 0, 0, 1, 1, 0, 1, 0, 0, 1, 0],
      [0, 0, 0, 1, 0, 0, 1, 1, 0, 0, 0, 1, 0, 0, 0, 0],
      [0, 0, 1, 1, 0, 0, 0, 0, 1, 1, 1, 0, 0, 0, 0, 0],
      [0, 0, 0, 0, 0, 0, 0, 0, 1, 0, 0, 0, 0, 0, 0, 0],
    ],
    '../static/images/animation/Babblingbrook1.gif',
  ),
  new Pattern(
    'Switch Engine',
    [
      [0, 1, 0, 1, 0, 0],
      [1, 0, 0, 0, 0, 0],
      [0, 1, 0, 0, 1, 0],
      [0, 0, 0, 1, 1, 1],
    ],
    '../static/images/animation/Switchengine.png',
  ),
  new Pattern(
    'Gosper Glider Gun',
    [
		[0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 1, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, ],
		[0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 1, 0, 1, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,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